const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    shid: 2,
    list: [],
    intPageCount: 1,
    intPageCurrent: 1,
    intPageSize: 15,
    noData: false,
    FjLoginLog: wx.getStorageSync('FjLoginLog')
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (app.checkFjLogin()) {
      this.setData({
        FjLoginLog: wx.getStorageSync('FjLoginLog')
      })
      this.getScList();
    } else {
      wx.redirectTo({ url: '../../pages/login/index' });
    }
  },
  shTab: function (e) {
    if (e.currentTarget.dataset.shid != this.data.shid) {
      this.setData({
        shid: e.currentTarget.dataset.shid,
        intPageCount: 1,
        noData: false,
        list: []
      })
      this.getScList();
    }
  },
  toInfo: function (e) {

    if (this.data.shid == 1) {
      wx.navigateTo({
        url: '../gongqiuxinxi/detailed?gqid=' + e.currentTarget.dataset.gqid,
      })
    } else if (this.data.shid == 2) {
      wx.navigateTo({
        url: '/packageA/pages/zichanchuzhi/detailed?gqid=' + e.currentTarget.dataset.gqid,
      })
    } else {
      wx.navigateTo({
        url: '../zhaobiaogonggao/detailed?uuid=' + e.currentTarget.dataset.gqid,
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.setData({
      list: [],
      intPageCount: 1
    })
    this.getScList();
    wx.stopPullDownRefresh()


  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (!this.data.noData) {
      this.getScList();
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  getScList: function () {
    if (this.data.FjLoginLog) {
      var that = this;
      var api_input = {
        LoginUserId: this.data.FjLoginLog.UID,
        type: this.data.shid,
        intPageCurrent: this.data.intPageCount,
        intPageSize: this.data.intPageSize,
      }
      app.getDaoPost('api/FeijiuApp/Post_FJ_GetChakanList', api_input, function (r) {
        console.log(r)
        if (r.code == 200) {
          var list1 = that.data.list.concat(r.data)
          for (var i = list1.length - 1; i >= 0; i--) {
            list1[i].addtime = app.dateformatT(list1[i].addtime, 10)
          }
          that.setData({
            list: list1
          })
          if (r.data.length > 1) {
            that.setData({
              intPageCount: that.data.intPageCount + 1
            })
          } else {
            that.setData({
              noData: true
            })
          }
        }
      })
    }
  }
})